from google.appengine.ext import db
from google.appengine.api import users

class Vocabulary(db.Model):
    #user = db.UserProperty()
    word = db.StringProperty(required=True)
    pronunciation  = db.StringProperty()
    #books = db.ListProperty(db.Key)
    #cards = db.ListProperty(db.Key)

class PublicBook(db.Model):
    bookname = db.StringProperty(required=True)
    description = db.StringProperty(multiline=True)
    level = db.IntegerProperty()
    createdTime = db.DateTimeProperty(auto_now_add=True)
    creator = db.UserProperty()
    #@property
    #def words(self):
    #    return Target.gql("WHERE books = :1", self.key())

class Dictionary(db.Model):
    word = db.ReferenceProperty(Vocabulary,required=True)
    book = db.ReferenceProperty(PublicBook,required=True)
    translation = db.StringProperty(required=True)

class Notebook(db.Model):
    user = db.UserProperty(required=True)
    word = db.ReferenceProperty(Vocabulary,required=True)
    book = db.ReferenceProperty(PublicBook)
    translation = db.StringProperty()

class HelperCard(db.Model):
    author = db.UserProperty(required=True)
    label = db.StringProperty(required=True, choices=set(["synonym", "similarity", "paronym","antonym","recipe","other"]))
    words = db.ListProperty(db.Key)
    content = db.StringProperty()

class CardRecommendation(db.Model):
    card = db.ReferenceProperty(HelperCard,required=True)
    word = db.ReferenceProperty(Vocabulary,required=True)
    vote = db.IntegerProperty(required=True)

class UserConfig(db.Model):
    user = db.UserProperty(required=True)
    currentBook = db.ReferenceProperty(PublicBook,required=True)